<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
    <script src="https://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/vue/2.4.4/vue.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.16.2/axios.min.js"></script>
</head>
<body>
	<form action="/api/login" method="post">
       用户名：<input type="text" name="email" value="1020472637@qq.com"></br>
       密  码：<input type="text" name="password" value="123456"></br>
       grant_type：<input type="text" name="grant_type" value="password"></br>
       client_id：<input type="text" name="client_id" value="1"></br>
       client_secret：<input type="text" name="client_secret" value="3468WUHLFAIaMVwmDROixmKZUkyVt7Y5mcw0RPen"></br>
       <input type="submit" value="提交">
    </form>
    <br/>
    <input type="button" value="获取access_token by password" onclick="getAuthToken();" >
    <input type="button" value="测试api接口get" onclick="getdata();" >
    <input type="button" value="测试api接口post" onclick="getdatapost();" >
    <input type="button" value="获取用户信息" onclick="getuser();" >
    <input type="button" value="测试api接口" onclick="getinfo();" >
    <input type="button" value="获取access_token by code" onclick="getToken();" >
</body>
</html>
<script type="text/javascript">
var p_token="";
function getAuthToken()
{
    $.ajax({
        url: '/api/v1/login',
        type: 'post',
        dataType: 'json',
        data: {
            'grant_type':'password',
            'client_id':'2',
            'client_secret':'mpwgIpOTPnbok1sziGaA185BEZQ2PO3wU9bKmVHC',
            'email':'1020472637@qq.com',
            'password':'123456',
            'scope':'',
         },
    })
    .done(function(data) {
        p_token=data.access_token;
        console.log("access_token:"+data.access_token);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    
}
function getToken()
{
    $.ajax({
        url: '/oauth/token',
        type: 'post',
        dataType: 'json',
        data: {
            'grant_type':'authorization_code',
            'client_id':'1',
            'client_secret':'zCqkel65rGW85Tc4eIBffF2WTUPm5LjeWablOoVw',
            'redirect_uri':'http://kf.mdshop.com',
            'code':'def5020017e713810b9f4112aed6a6dcd3a296146ef866a5dc8bd629bafef49fb37c3c78039e20cbbca75cafe36b54fa2dad848863dcc0b6b0397f9c631cc78e0cb41f25a38fe720d8f40446edbfed456fcd6fe70136ce172a403c9553a4d345c1ed08eabfe159c4cf34706a22db680156403757656c9ece1de58b9a4b7f4e70f015bbf633ff3be174f4f6cf6f6a3a6e9b430518e1fc53713ab6c52bb0b64c6a41d33fca764614ecbc7cdbcff05f5060555159d2617e3a395a5400dcb9626517ea0bb43caf1f41b6abec2bb268634596e2cf8cb40c5af813c8e8f827a3fa9c01bd7eddd41a5a0a0595fd19adc8681d34bf6413e23f87696c5995b8f0c4b54cf78148c60a15ac4f9d2ce726b5c473c9fb74167a6a18d8e9ade508513971640f40b4c0e1f8f53dde2191a1700973dc9dcce8c42697c3fa75cd075a158380f07f402f7ac714c26c921b053dcd7241d361371261b79bc586',
         },
    })
    .done(function(data) {
        p_token=data.access_token;
        console.log("access_token:"+data.access_token);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    
}
function getdata()
{
       $.ajax({
        url: '/api/v1/getdata',
        type: 'get',
        dataType: 'json',
        headers:{'Accept':'application/json',"Authorization":'Bearer '+p_token},
        data: {},
    })
    .done(function(data) {
        alert(data);
        console.log(data);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
}


function getinfo()
{
       $.ajax({
        url: '/api/v1/getinfo',
        type: 'get',
        dataType: 'json',
        data: {},
    })
    .done(function(data) {
        alert(data);
        console.log(data);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
}

function getuser()
{
       $.ajax({
        url: '/api/v1/getUserInfo',
        type: 'get',
        dataType: 'json',
        headers:{'Accept':'application/json',"Authorization":'Bearer '+p_token},
        data: {},
    })
    .done(function(data) {
        alert(data);
        console.log(data);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
}

function getdatapost()
{
       $.ajax({
        url: '/api/v1/index/getdata',
        type: 'post',
        dataType: 'json',
        headers:{'Accept':'application/json',"Authorization":'Bearer '+p_token},
        data: {},
    })
    .done(function(data) {
        alert(data);
        console.log(data);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
}
</script>
 <script type="text/javascript">
/*const data = {
   name: 'md_slb_api',
   redirect: 'http://kf.mdshop.com',
   password_client:'1',
};

axios.post('/oauth/clients', data)
   .then(response => {
       console.log(response.data);
   })
   .catch (response => {
       // List errors on response...
   });*/
axios.get('/oauth/clients')
   .then(response => {
       console.log(response.data);
   });
</script>